import os
import time
import unittest
from page.admin_index_page import IndexPage
from common.base import get_driver
from selenium.webdriver.common.by import By


class AddGoodCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 类夹具定义登录
        driver = get_driver()
        driver.get('http://localhost:8080/ecshop/admin/index.php')
        cls.test = IndexPage(driver)
        cls.test.click((By.XPATH, '//span[@onclick]'))
        cls.test.click((By.ID, 'cloudLogin'))
        cls.test.send_keys((By.NAME, 'username'), 'root1234')
        cls.test.send_keys((By.NAME, 'password'), 'root1234')
        cls.test.click((By.XPATH, '//input[@type="submit"]'))
        time.sleep(2)

    def test_01_add_good(self):
        # TODO 只点选必填项操作流程
        self.test.to_left_menu()
        self.test.to_goods_manage()
        self.test.to_main_menu()

        goods_name = "七匹狼超人同款内裤"
        self.test.input_name(goods_name)

        self.test.choice_type()
        self.test.input_price("19.9")
        self.test.make_sure()

        # TODO 断言
        """
        预期 和 实际结果 的比对
        """
        # 定位预期结果
        time.sleep(6)
        real_good_name = self.test.get_text((By.CLASS_NAME,"first-cell"))
        self.assertEqual(goods_name, real_good_name, msg="商品添加失败")
        # 完成退出浏览器
        self.test.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
